<%@ page language="java" contentType="text/html; charset=UTF-8"
    pageEncoding="UTF-8"%>
<%@ taglib prefix="s" uri="/struts-tags" %>
<%@ taglib prefix="fmt" uri="http://java.sun.com/jsp/jstl/fmt" %>
<!DOCTYPE html PUBLIC "-//W3C//DTD HTML 4.01 Transitional//EN" "http://www.w3.org/TR/html4/loose.dtd">
<html>
<head>
<meta http-equiv="Content-Type" content="text/html; charset=UTF-8">

    <link href="${ctx}/css/style.css" type="text/css" rel="stylesheet" /> 
    <link href="${ctx}/js/ztree/css/demo.css" type="text/css" rel="stylesheet">
    <link href="${ctx}/js/ztree/css/zTreeStyle/zTreeStyle.css" type="text/css" rel="stylesheet">
    <script src="${ctx}/js/jquery-1.7.2.min.js" type="text/javascript"></script>
    <script src="${ctx}/js/jquery.cookie.js" type="text/javascript"></script>
    <script src="${ctx}/js/jquery.treeview.js" type="text/javascript"></script>
    <script type="text/javascript" src="${ctx}/js/ztree/js/jquery.ztree.core-3.3.min.js"></script>
    <script type="text/javascript" src="${ctx}/js/ztree/js/jquery.ztree.excheck-3.3.min.js"></script>
  
    <title>安全系统—角色列表</title>
<body>
  <div class="m_right">
    
    <div class="m_r_tips">
     <div class="m_r_lefttips">您现在的位置：<a href="${ctx}/admin/home.jsp">首页</a>&gt;用户权限管理&gt;查看角色权限</div>
        <jsp:include page="/commons/admin/admin_login_remind.jsp"/>
    </div>
    
    <s:if test="hasActionMessages()">
          <div class="success">
               <s:actionmessage/>
          </div>
    </s:if>
     <s:if test="hasActionErrors()">
          <div class="error">
               <s:actionerror/>
          </div>
    </s:if>
    <div style="color:red">
        <s:fielderror />
    </div>
    <div style="font-size: 14px;font-weight: bolder;padding: 10px 20px;">
        角色名：${role.roleName}
    </div>
    <div class="zTreeDemoBackground left fl">
        <ul id="permTree" class="ztree"></ul>
    </div>
    <!-- role id hidden -->
    
    <input type="hidden" name="rid" value="${rid}" id="rid" />
   
     <!--<s:hidden name="role.rid"  value="%{rid}" id="rid"/>  -->
</div>
</body>
  <SCRIPT type="text/javascript">
        <!--
        var setting = {
        		
            check: {
                enable: false
//                chkboxType: { "Y" : "", "N" : "" }
            },  
      

            data: {
                 simpleData: {
                     enable: true
                 }
            },
            /**
            async: {
                enable: true,
                url:"async.jsp",
                autoParam:["id", "name", "level=lv"],
                otherParam:{"otherParam":"zTreeAsyncTest"},
                dataFilter: filter
            },        **/
            callback:{
//                     onClick:function(event, treeId, treeNode, clickFlag){ if(!treeNode.isParent) alert(treeNode.id + " " +treeNode.value + " " + treeNode.chkDisabled + " " + treeNode.checked);}
                    //onCheck: function(event, treeId, treeNode){if(!treeNode.isParent)  alert(treeId + " " +treeNode.value  + " " + treeNode.pId);},
                    //beforeExpand: beforeExpand,
                    //onExpand: onExpand
             }
        };

       var treeData = '${menTree}';      
       var zNodes = eval('('+treeData+')');

        function filter(treeId, parentNode, childNodes) {
            if (!childNodes) return null;
            for (var i=0, l=childNodes.length; i<l; i++) {
                childNodes[i].name = childNodes[i].name.replace(/\.n/g, '.');
            }
            return childNodes;
        }
        
        
        var curExpandNode = null;
        function beforeExpand(treeId, treeNode) {
            var pNode = curExpandNode ? curExpandNode.getParentNode():null;
            var treeNodeP = treeNode.parentTId ? treeNode.getParentNode():null;
            var zTree = $.fn.zTree.getZTreeObj("permTree");
            for(var i=0, l=!treeNodeP ? 0:treeNodeP.children.length; i<l; i++ ) {
                if (treeNode !== treeNodeP.children[i]) {
                    zTree.expandNode(treeNodeP.children[i], false);
                }
            }
            while (pNode) {
                if (pNode === treeNode) {
                    break;
                }
                pNode = pNode.getParentNode();
            }
            if (!pNode) {
                singlePath(treeNode);
            }

        }
        function singlePath(newNode) {
            if (newNode === curExpandNode) return;
            if (curExpandNode && curExpandNode.open==true) {
                var zTree = $.fn.zTree.getZTreeObj("permTree");
                if (newNode.parentTId === curExpandNode.parentTId) {
                    zTree.expandNode(curExpandNode, false);
                } else {
                    var newParents = [];
                    while (newNode) {
                        newNode = newNode.getParentNode();
                        if (newNode === curExpandNode) {
                            newParents = null;
                            break;
                        } else if (newNode) {
                            newParents.push(newNode);
                        }
                    }
                    if (newParents!=null) {
                        var oldNode = curExpandNode;
                        var oldParents = [];
                        while (oldNode) {
                            oldNode = oldNode.getParentNode();
                            if (oldNode) {
                                oldParents.push(oldNode);
                            }
                        }
                        if (newParents.length>0) {
                            for (var i = Math.min(newParents.length, oldParents.length)-1; i>=0; i--) {
                                if (newParents[i] !== oldParents[i]) {
                                    zTree.expandNode(oldParents[i], false);
                                    break;
                                }
                            }
                        } else {
                            zTree.expandNode(oldParents[oldParents.length-1], false);
                        }
                    }
                }
            }
            curExpandNode = newNode;
        }

        function onExpand(event, treeId, treeNode) {
            curExpandNode = treeNode;
        }

        $(document).ready(function(){
        	//alert(zNodes);
            $.fn.zTree.init($("#permTree"), setting,zNodes);
        });
        
        function auth_permissions() {
            var treeObj = $.fn.zTree.getZTreeObj("permTree");
            //alert(treeObj);
            var nodes = treeObj.getCheckedNodes(true);
        	//alert(nodes);
            if (nodes.length == 0) {
        	    alert("未选择任何框框");        		
        	    return;
        	}
        	var permissions_values = "";
        	for (var i=0; i<nodes.length; i++) {
                   permissions_values = permissions_values + nodes[i].value + "#";
            };
            window.location.href = "${ctx}/admin/role/addRolePerm.do?rid=" + $("#rid").val() + "&perm-values=" + escape(permissions_values);
//            window.location.href = "${ctx}/admin/role/addRolePerm.do?perm-values=" + escape(permissions_values);
        }
        
        
        //-->
    </SCRIPT>
</html>
